class MusicPlayer {
  private val playlist = scala.collection.mutable.ListBuffer[String]()
  private var currentSong: Option[String] = None
  private var playMode: String = "normal"

  def addSong(song: String): Unit = {
    playlist += song
    println(s"Added '$song' to the playlist.")
  }

  def removeSong(song: String): Unit = {
    if (playlist.contains(song)) {
      playlist -= song
      println(s"Removed '$song' from the playlist.")
    } else {
      println(s"'$song' is not in the playlist.")
    }
  }

  def play(): Unit = {
    if (playlist.nonEmpty) {
      if (currentSong.isEmpty) {
        currentSong = Some(playlist.head)
        println(s"Playing '${currentSong.get}'.")
      } else {
        val currentIndex = playlist.indexOf(currentSong.get)
        playMode match {
          case "normal" =>
            if (currentIndex == playlist.length - 1) {
              currentSong = Some(playlist.head)
            } else {
              currentSong = Some(playlist(currentIndex + 1))
            }
          case "repeat" =>
            if (currentIndex == playlist.length - 1) {
              currentSong = Some(playlist.head)
            } else {
              currentSong = Some(playlist(currentIndex + 1))
            }
          case "shuffle" =>
            currentSong = Some(playlist(scala.util.Random.nextInt(playlist.length)))
        }
        println(s"Playing '${currentSong.get}'.")
      }
    } else {
      println("The playlist is empty.")
    }
  }

  def setPlayMode(mode: String): Unit = {
    playMode = mode
    println(s"Play mode set to '$mode'.")
  }

  def printPlaylist(): Unit = {
    println("Playlist:")
    playlist.foreach(song => println(song))
